import 'package:flutter/material.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/quota/controller/quota_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/extension/widget_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';

class QuotaPage extends BaseState<QuotaController> {
  @override
  QuotaController initController() => QuotaController();

  @override
  Widget initView(BuildContext context) {
    return Container(
      color: Colors.white,
      width: Get.width,
      height: Get.height,
      child: Column(
        children: [
          103.heightBox,
          Row(
            children: [
              49.widthBox,
              ImageCommon(
                "/icon/ic_left",
                width: 21.width,
                height: 36.width,
              ).addClickEvent(() => Get.back()),
              30.widthBox,
              TextCommon(
                "实时行情",
                size: 36.sp,
                fontWeight: FontWeight.bold,
                color: Color(0xFF242429),
              ),
              Spacer(),
              ImageCommon(
                "/icon/quota_warn",
                size: 25.sp,
                fit: BoxFit.fill,
              ),
              10.widthBox,
              TextCommon(
                "行情数据取自交易所，仅供参考",
                size: 22.sp,
                color: Color(0xFF6C727D),
              ),
              49.widthBox,
            ],
          ),
          25.heightBox,
          Container(
            padding: MarginPaddingUtil.symmetric(horizontal: 40, vertical: 17),
            color: Color(0xFFF6F6F6),
            child: Row(
              children: [
                TextCommon(
                  "名称代码",
                  size: 22.sp,
                  color: Color(0xFF6C727D),
                ),
                Spacer(),
                TextCommon(
                  "最新价",
                  size: 22.sp,
                  color: Color(0xFF6C727D),
                ),
                15.widthBox,
                ImageCommon(
                  "/icon/quota_filter",
                  width: 15.sp,
                  height: 25.sp,
                  fit: BoxFit.fill,
                ),
                67.widthBox,
                TextCommon(
                  "24h涨跌幅",
                  size: 22.sp,
                  color: Color(0xFF6C727D),
                ),
                15.widthBox,
                ImageCommon(
                  "/icon/quota_filter",
                  width: 15.sp,
                  height: 25.sp,
                  fit: BoxFit.fill,
                )
              ],
            ),
          ),
          31.heightBox,
          Expanded(
            child: ListView.separated(
              padding: EdgeInsets.zero,
              itemCount: controller.bean?.list?.length ?? 0,
              itemBuilder: (context, index) {
                final item = controller.bean!.list![index];
                return Row(
                  children: [
                    40.widthBox,
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        TextCommon(
                          item.symbol ?? "",
                          size: 24.sp,
                          fontWeight: FontWeight.bold,
                        ),
                        13.heightBox,
                        TextCommon(
                          item.code ?? "",
                          size: 22.sp,
                          color: Color(0xFF707070),
                        ),
                      ],
                    ),
                    Spacer(),
                    TextCommon(
                      "${item.latestPrice ?? ""}",
                      size: 32.sp,
                      fontWeight: FontWeight.bold,
                    ),
                    77.widthBox,
                    Container(
                      padding: MarginPaddingUtil.symmetric(
                          vertical: 13, horizontal: 30),
                      decoration: BoxDecoration(
                        color: (item.changeRate ?? 0) > 0
                            ? Color(0xFFFC7676)
                            : Color(0xFF00AA7C),
                        borderRadius: BorderRadius.circular(10.sp),
                      ),
                      child: TextCommon(
                        "${((item.changeRate ?? 0) * 100).toStringAsFixed(2)}%",
                        size: 28.sp,
                        color: Colors.white,
                      ),
                    ),
                    40.widthBox,
                  ],
                );
              },
              separatorBuilder: (BuildContext context, int index) =>
                  30.heightBox,
            ),
          ),
        ],
      ),
    );
  }
}
